package com.jingdianjichi.club.oss.service;

import com.jingdianjichi.club.oss.adapter.StorageAdapter;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 抽取一层,避免改动底层实现的时候,影响业务代码
 * @author 86156
 * @version 1.0
 * @date 2024-10-25 14:30
 */
@Service
public class FileService {

    private final StorageAdapter storageAdapter;

    public FileService(StorageAdapter storageAdapter) {
        this.storageAdapter = storageAdapter;
    }

    /**
     * 列出所有的 bucket
     */
    public List<String> listBucket() throws Exception {
        return storageAdapter.listBucket();
    }

    public String uploadFile(MultipartFile file, String bucketName, String objectName) {
        storageAdapter.uploadFile(file, bucketName, objectName);
        return storageAdapter.getUrl(bucketName,objectName);
    }

}
